<?php require_once(dirname(__FILE__).'/../include/config.inc.php');
require_once "function.php";
/*
进度：
0 已经撤单
1 报修成功
2 客服已经联系
3 系统已经派单
4 工程师接单
5 维修完成
6 已经评价
*/
$jindu= empty($jindu) ? '' : htmlspecialchars($jindu); //进度状态
$jindu=intval($jindu);
$apply_type= empty($apply_type) ? '' : htmlspecialchars($apply_type); //服务类型


if($apply_type=='1' ||  $apply_type==''  ){
	switch ($jindu)
	{
		case 1:
		  $order_title="报修成功";
		  break;
		case 3:
		  $order_title="已派单";
		  break;
		case 4:
		  $order_title="维修中";
		  break;
		case 5:
		  $order_title="已完成";
		  break;
		case 6:
		  $order_title="已评价";
		  break; 
		default:
		  $order_title="全部";
	}
}
if($apply_type=='2'){
	switch ($jindu)
	{
		case 1:
		  $order_title="提交成功";
		  break;
		case 3:
		  $order_title="配货完成";
		  break;
		case 4:
		  $order_title="配送中";
		  break;
		case 5:
		  $order_title="已送达";
		  break;
		case 6:
		  $order_title="已评价";
		  break; 
		default:
		  $order_title="全部";
	}
}


?>
<!DOCTYPE html>
<html>
<head>
<title>工单列表 <?php echo $cfg_webname;?> </title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="<?php echo $cfg_webname;?>">
<link rel="stylesheet" href="lib/weui.min.css">
<link rel="stylesheet" href="css/jquery-weui.css">
<link rel="stylesheet" href="css/font-awesome.min.css">
<link rel="stylesheet" href="css/demos.css">
</head>

<body ontouchstart>
<div class="top"> <img src="images/top.jpg" width="100%"> </div>
<!-- 地址信息 --> 
  <!--工单详情开始-->
<!--工单详情开始-->
<div class="main">
  <div class="weui-cells__title"><i class="fa fa-id-card-o" aria-hidden="true"></i>我的 <?php echo $order_title."--".getTypeName($apply_type);?> 列表</div>
  <!--工单列表开始-->
				<?php
				$sql="SELECT * FROM `#@__order`   WHERE is_delete=0  AND  uid='$uid'  AND ";
				if(empty($jindu)){	
					$sql.=" jindu>'0'  ";
				 }else{	
					 if($jindu=='5'){
						 $sql.="  `jindu`>4  ";	
					 }else{
						 $sql.="  `jindu`='$jindu'  ";	
					}
				 } //进度
				if(empty($apply_type)){	 }else{	$sql.=" AND  apply_type='$apply_type'  ";	} //进度
				$sql.= "ORDER BY id DESC";
				$dopage->GetPage($sql,8);
				while($row = $dosql->GetArray())
				{
					/*
					进度：
					0 已经撤单
					1 报修成功
					2 客服已经联系
					3 系统已经派单
					4 工程师接单
					5 维修完成
					6 已经评价
					*/
					$orderid=$row['id'];
					$jindu2=intval($row['jindu']);
					$apply_type=$row['apply_type'];
					$apply_device=$row['apply_device'];
					




					if($jindu2==1){
						$op_str='
        <button type="submit" class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" onClick="chedan('.$row['id'].')"><i class="fa fa-times" aria-hidden="true"></i>取消</button><a class="weui-form-preview__btn weui-form-preview__btn_primary" href="javascript:" onClick="cuidan('.$row['id'].')"><i class="fa fa-thumb-tack" aria-hidden="true"></i>催单</a><a class=weui-form-preview__btn weui-form-preview__btn_primary" href="orderDetail.php?orderid='.$row['id'].'" ><i class="fa fa-navicon" aria-hidden="true"></i>详情</a>';
					}elseif($jindu2==5){
						$op_str='
        <a class="weui-form-preview__btn weui-form-preview__btn_primary" href="pingjia.php?orderid='.$row['id'].' "><i class="fa fa-thumb-tack" aria-hidden="true"></i>评价</a><a class=weui-form-preview__btn weui-form-preview__btn_primary" href="orderDetail.php?orderid='.$row['id'].'" ><i class="fa fa-navicon" aria-hidden="true"></i>详情</a>';	
					}else{
						$op_str='<a class=weui-form-preview__btn weui-form-preview__btn_primary" href="orderDetail.php?orderid='.$row['id'].'" ><i class="fa fa-navicon" aria-hidden="true"></i>详情</a>';
					}

					

				?>
  
  <!--工单详情开始-->
  <div class="weui-form-preview">
    <div class="weui-form-preview__bd">
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">工单号：</label>
        <span class="weui-form-preview__value">
		<?php 
		if(!empty($row['poster'])) { 
		echo '<i class="fa fa-smile-o blue "></i>';
		}
		if(!empty($row['openid'])) { 
		echo '<i class="fa fa-weixin green"></i>';
		}		
		?>
        <?php echo date("Ymd",$row['post_time'])."-".$row['id']?>
        </span>   
        </div>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">单位：</label>
        <span class="weui-form-preview__value"><?php echo $row['school']?></span> </div>
        <?php if(!empty($row['truename'])){?>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">联系人：</label>
        <span class="weui-form-preview__value"><?php echo $row['truename']?></span> </div>
        <?php }?>
        <?php if(!empty($row['mobile'])){?>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">电话：</label>
        <span class="weui-form-preview__value"><a href="tel:<?php echo $row['mobile']?>"><i class="fa fa-mobile"><?php echo $row['mobile']?></a></i></span> </div>
        <?php }?>
        <?php if(!empty($row['address'])){?>
        <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">地址：</label>
        <span class="weui-form-preview__value" id="daohang" data-orderid="<?php echo $row['id']?>"><i class="fa fa-map-marker" ><?php echo $row['address']?></i></span> </div>
        <?php }?>


        <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">服务类型：</label>
            <span class="weui-form-preview__value"><i class="fa  fa-drivers-license-o red"></i> <?php echo getRepairMode($row['apply_device']) ?></span>
        </div>


      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">描述：</label>
        <span class="weui-form-preview__value"><?php echo $row['content']?></span> </div>
         <?php if(!empty($row['manageid'])){?>
      <div class="weui-form-preview__item">
        <label class="weui-form-preview__label">执行人：</label>
        <span class="weui-form-preview__value">
			<?php 
			if(!empty($row['manageid'])){
				$m_str=$row['manageid'];
				$m_arr=explode(",",$m_str);
				foreach($m_arr as $key=>$val){
					echo ' <i class="fa  fa-user-o red"></i>      '.getManage($val);
				}
			}
			?>
        
        </span> </div>
        <?php } ?>
              <div class="weui-form-preview__item">
        <label class="weui-form-preview__label red">当前进度：</label>
        <span class="weui-form-preview__value red"><b><?php echo getJinDuName($row['jindu'])?></b></span> 
        </div>
    </div>
    <div class="weui-form-preview__ft op"> <?php echo $op_str?> </div>
  </div>
  <!--工单详情结束-->
  
  <?php }?>
  
  <!--工单列表结束--> 
</div>

		<div class="page-div">

        <?php echo $dopage->GetList(); ?>

        </div>

<div class="clear"></div>
<div class="sub_btn"></div>
<script src="lib/jquery-2.1.4.js"></script> 
<script src="lib/fastclick.js"></script> 
<script>
  $(function() {
    FastClick.attach(document.body);
  });
  
  
  
  function cuidan(id){
	  $.ajax({
		  type: 'POST',
		  url: "op.php",
		  data: {id:id,op:'cui'},
		  dataType: 'JSON',
		  success:function(result){
		  console.log(result);
			if(result.errno==0){
				 console.log(result.msg);
				if(result.msg==="ok"){
					$.toast("催单成功", function() {
					 console.log('close');
					});
					
				}else{
					 $.alert("小主，请耐心等待<br/> 30分钟后可以催单哦！", "温馨提示");
				}
			}
		  }
	  });
	  
  }
  function chedan(id){
	  $.ajax({
		  type: 'POST',
		  url: "op.php",
		  data: {id:id,op:'che'},
		  dataType: 'JSON',
		  success:function(result){
		  console.log(result);
			if(result.errno==0){
				 console.log(result.msg);
				if(result.msg==="ok"){
					$.toast("取消工单成功", function() {
					 window.location.reload();
					});
					
				}else{
					 $.alert("小主，你的工单已经在处理中...<br/> 不能取消工单哦！", "温馨提示");
				}
			}
		  }
	  });
	  
  }
  
</script> 
<script src="js/jquery-weui.js"></script> 
<?php require_once('footer.php'); ?>